'''
@project:pythonProjectT174
@auther:zhongyingjie
@file:tysphd_tjkh.py
@date:2022/11/5 18:37
@desc:
'''
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
import unittest
from selenium.webdriver.support.ui import Select
from common.broswersetting import broswersetting
class tjyh(broswersetting):
    # def setUp(self) -> None:
    #     self.driver = webdriver.Chrome()  # 创建一个浏览器对象
    #     self.driver.get('http://192.168.186.111/tinyshop/index.php?con=admin&act=login')
    #     self.driver.maximize_window()
    #     self.driver.find_element(By.XPATH,'//input[@name="name"]').send_keys('admin')
    #     self.driver.find_element(By.XPATH,'//input[@name="password"]').send_keys('123456')
    #     self.driver.find_element(By.XPATH,'//input[@name="verifyCode"]').send_keys('aaaa')
    #     self.driver.find_element(By.XPATH,'//input[@value="登 录"]').click()
    #     self.driver.find_element(By.XPATH, '//a[text()="客户中心"]').click()
    #     self.driver.find_element(By.CLASS_NAME, 'icon-plus').click()
    # def tearDown(self) -> None:
    #     self.driver.quit()
    def test_tjkh1(self):
        self.tiny_htzh('admin','123456','aaaa')
        self.tjyh('zxc111','123456','123456','22@qq.com','张三','1998-10-21')
        a=self.driver.page_source
        try:
            self.assertIn('zxc111',a)
        except Exception as e:
            self.driver.get_screenshot_as_file('F:\\csxm\\tinyshop_t174\\images\\hytj1.png')
    def test_tjkh2(self):
        # self.driver.find_element(By.XPATH, '//input[@pattern="\w{6,}"]').send_keys('123456')
        # self.driver.find_element(By.NAME, 'repassword').send_keys('123456')
        # self.driver.find_element(By.NAME, 'email').send_keys('123@qq.com')
        # self.driver.find_element(By.NAME, 'real_name').send_keys('张三')
        # self.driver.find_element(By.NAME, 'birthday').send_keys('1997-8-18')
        # se = self.driver.find_element(By.XPATH, '//select[@id="province"]')
        # se1 = self.driver.find_element(By.XPATH, '//select[@id="city"]')
        # se2 = self.driver.find_element(By.XPATH, '//select[@id="county"]')
        # s = Select(se)
        # s1 = Select(se1)
        # s2 = Select(se2)
        # time.sleep(2)
        # s.select_by_visible_text('湖南省')
        # time.sleep(2)
        # s1.select_by_visible_text('株洲市')
        # time.sleep(2)
        # s2.select_by_visible_text('芦淞区')
        # time.sleep(2)
        # self.driver.find_element(By.XPATH, '//input[@value="提交"]').submit()
        # time.sleep(2)
        self.tiny_htzh('admin', '123456', 'aaaa')
        self.tjyh('', '123456', '123456', '22@qq.com', '张三', '1998-10-21')
        a = self.driver.find_element(By.XPATH, '//*[@id="obj_form"]/form/dl[1]/dd/label').text
        try:
            self.assertIn('用户名称（必填）', a)
        except Exception as e:
            self.driver.get_screenshot_as_file('F:\\csxm\\tinyshop_t174\\images\\hytj2.png')
    def test_tjkh3(self):

        self.tiny_htzh('admin', '123456', 'aaaa')
        self.tjyh('zxc', '', '', '22@qq.com', '张三', '1998-10-21')
        a = self.driver.find_element(By.XPATH, '//*[@id="obj_form"]/form/dl[2]/dd/label').text
        try:
            self.assertIn('密码必需大于6位', a)
        except Exception as e:
            self.driver.get_screenshot_as_file('F:\\csxm\\tinyshop_t174\\images\\hytj3.png')

    def test_tjkh4(self):

        self.tiny_htzh('admin', '123456', 'aaaa')
        self.tjyh('zxc', '123456', '123122', '22@qq.com', '张三', '1998-10-21')
        a = self.driver.find_element(By.XPATH, '//*[@id="obj_form"]/form/dl[3]/dd/label').text
        try:
            self.assertIn('两次输入密码不一致', a)
        except Exception as e:
            self.driver.get_screenshot_as_file('F:\\csxm\\tinyshop_t174\\images\\hytj4.png')
    def test_tjkh5(self):

        self.tiny_htzh('admin', '123456', 'aaaa')
        self.tjyh('zxc', '123456', '123456', '33.com', '张三', '1998-10-21')
        a = self.driver.find_element(By.XPATH, '//*[@id="obj_form"]/form/dl[4]/dd/label').text
        try:
            self.assertIn('邮箱地址(例如:tiny@tiny.com)', a)
        except Exception as e:
            self.driver.get_screenshot_as_file('F:\\csxm\\tinyshop_t174\\images\\hytj5.png')
if __name__=='__main__':
    unittest.main()
